package com.zhouyu.redisExample.redission.template;

import com.zhouyu.redisExample.entity.RedisUserEntity;
import com.zhouyu.redisExample.redission.UserRedisOperator;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.function.Supplier;

/**
 * Description:
 * redis操作共用类
 * @author zhouyu
 * @date 2022/2/25 14:34
 */
public class RedisUserService{
    @Resource
    RedisTemplate redisTemplate;

    public RedisUserEntity get(String key, Supplier<RedisUserEntity> supplier) {
        RedisUserEntity redisUser = (RedisUserEntity) redisTemplate.opsForValue().get(key);
        if(redisUser==null){
            redisUser = supplier.get();
            /**具体函数干什么，在调用时*/
            setUserRedis(user->{});
        }
        return redisUser;
    }

    public void setUserRedis(UserRedisOperator<RedisUserEntity> userRedisOperator){
        RedisUserEntity redisUserEntity = new RedisUserEntity();
        userRedisOperator.setUser(redisUserEntity);
    }
}
